import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number
  race: string // 种族
  affix: string // 属性
  name: string // 掉落物品
  amount: number // 掉落数量
  require_level: number // 需求等级
  base_rate: number // 基础概率
  level_rate: number // 等级概率
}
class drop_list extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

drop_list.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      allowNull: false,
      comment: '自增主键'
    },
    race: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '种族'
    },
    affix: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '属性'
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '掉落物品'
    },
    amount: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '掉落数量'
    },
    require_level: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '需求等级'
    },
    base_rate: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '基础概率'
    },
    level_rate: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '等级概率'
    }
  },
  {
    sequelize,
    tableName: 'drop_list',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      }
    ]
  }
)
export { drop_list }
